#ifndef _CACHE_H
#define _CACHE_H
#include <sys/types.h>
#include <time.h>
#include <sys/stat.h>
#include "url_info.h"


#define FD_TIMEOUT 4 
#define DISK_MAGIC 0xa8f43b0e
struct disk_fmt {
        u_int32_t ver; /* must be set to 1 */
        u_int32_t headlen;
        u_int32_t filelen;
        u_int32_t magic; /* validation check */
};

struct curlblock
{
	int sock;
	int flag;
	FILE *f;
#define BLK_F_200 1
#define BLK_F_302 1<<1
#define BLK_F_LEN 1<<2
#define BLK_F_TRUNK 1<<3
	u_int head_len;
	u_int file_len;
	struct url_info *url;
};

struct dl_task {
	struct url_info *url_info;
	struct disk_fmt *disk;
	unsigned int from, to; /* @to point to the byte after the content, where @from start from zero */
	unsigned int total; /* 0 mean not determined */
	int use206; /* if use partial content response */
};





extern time_t last_send_time;
extern struct conf *gconf;
void new_send_data(int fid, int socket_id, struct dl_task *dl_task);
int nonblocking_r(int fd, int timeout);
int nonblocking_w(int fd, int timeout);
void cache_response(int sock, int fd, struct url_info *url_info, struct disk_fmt *disk_fmt) ;
int get_range(char *range, unsigned int *from, unsigned int *to, unsigned int file_len);
int file_fresh(struct stat *st);




#endif
